package com.ruoyi.web.controller.fantasy;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.IdWorker;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.huanzhidadi.fantasy.bean.domain.FantasyBankAccountFlow;
import com.ruoyi.fantasy.service.IFantasyBankAccountFlowService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账户流水Controller
 * 
 * @author wanghui
 * @date 2020-06-18
 */
@Controller
@RequestMapping("/fantasy/fantasyBankAccountFlow")
public class FantasyBankAccountFlowController extends BaseController
{
    private String prefix = "fantasy/fantasyBankAccountFlow";

    @Autowired
    private IFantasyBankAccountFlowService fantasyBankAccountFlowService;

    @RequiresPermissions("fantasy:fantasyBankAccountFlow:view")
    @GetMapping()
    public String flow()
    {
        return prefix + "/fantasyBankAccountFlow";
    }

    /**
     * 查询账户流水列表
     */
    @RequiresPermissions("fantasy:fantasyBankAccountFlow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FantasyBankAccountFlow fantasyBankAccountFlow)
    {
        startPage();
        List<FantasyBankAccountFlow> list = fantasyBankAccountFlowService.selectFantasyBankAccountFlowList(fantasyBankAccountFlow);
        return getDataTable(list);
    }

    /**
     * 导出账户流水列表
     */
    @RequiresPermissions("fantasy:fantasyBankAccountFlow:export")
    @Log(title = "账户流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FantasyBankAccountFlow fantasyBankAccountFlow)
    {
        List<FantasyBankAccountFlow> list = fantasyBankAccountFlowService.selectFantasyBankAccountFlowList(fantasyBankAccountFlow);
        ExcelUtil<FantasyBankAccountFlow> util = new ExcelUtil<FantasyBankAccountFlow>(FantasyBankAccountFlow.class);
        return util.exportExcel(list, "flow");
    }

    /**
     * 新增账户流水
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存账户流水
     */
    @RequiresPermissions("fantasy:fantasyBankAccountFlow:add")
    @Log(title = "账户流水", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FantasyBankAccountFlow fantasyBankAccountFlow)
    {
        fantasyBankAccountFlow.setId(String.valueOf(IdWorker.nextId()));
        fantasyBankAccountFlow.setCreateTime(new Date());
        return toAjax(fantasyBankAccountFlowService.insertFantasyBankAccountFlow(fantasyBankAccountFlow));
    }

    /**
     * 修改账户流水
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        FantasyBankAccountFlow fantasyBankAccountFlow = fantasyBankAccountFlowService.selectFantasyBankAccountFlowById(id);
        mmap.put("fantasyBankAccountFlow", fantasyBankAccountFlow);
        return prefix + "/edit";
    }

    /**
     * 修改保存账户流水
     */
    @RequiresPermissions("fantasy:fantasyBankAccountFlow:edit")
    @Log(title = "账户流水", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FantasyBankAccountFlow fantasyBankAccountFlow)
    {
        return toAjax(fantasyBankAccountFlowService.updateFantasyBankAccountFlow(fantasyBankAccountFlow));
    }

    /**
     * 删除账户流水
     */
    @RequiresPermissions("fantasy:fantasyBankAccountFlow:remove")
    @Log(title = "账户流水", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fantasyBankAccountFlowService.deleteFantasyBankAccountFlowByIds(ids));
    }
}
